package net.lbtech.client;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;


public class SimpleChatClient {
    public static void main(String[] args) throws Exception{
            new SimpleChatClient("192.168.0.199", 9999).run();
        }

        private final String host;
        private final int port;

        public SimpleChatClient(String host, int port){
            this.host = host;
            this.port = port;
        }

        public void run() throws Exception{
            EventLoopGroup group = new NioEventLoopGroup();
            try {
                Bootstrap bootstrap  = new Bootstrap()
                        .group(group)
                        .channel(NioSocketChannel.class)
                        .handler(new SimpleChatClientInitializer());
                Channel channel = bootstrap.connect(host, port).sync().channel();
                byte[] a = new byte[20];
                a[0]=(byte)0xF5;
                a[1]=0x03;
                a[2]=125;//头
                a[3]=21;
                a[4]=85;
                a[5]=91;
                a[6]=110;
                a[7]=125;//末
                a[19]=127;
                while(true){

                    channel.writeAndFlush(a);
                    Thread.sleep(100000);
                }

            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                group.shutdownGracefully();
            }

        }
    }

